package com.example.administrator.yuejian2.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.NumberPicker;
import android.widget.TextView;

import com.example.administrator.yuejian2.R;
import com.example.administrator.yuejian2.RetrofitListener.RetrofitListener;
import com.example.administrator.yuejian2.bean.TrainBean;
import com.example.administrator.yuejian2.model.TrainDetailModel;
import com.squareup.picasso.Picasso;

import butterknife.BindView;
import butterknife.ButterKnife;

import static com.example.administrator.yuejian2.other.Url.IMAGEURL;

public class TrainDetailActivity extends BaseActivity {

    @BindView(R.id.train_detail_pic)
    ImageView trainDetailPic;
    @BindView(R.id.train_detail_name)
    TextView trainDetailName;
    @BindView(R.id.train_detail_intro)
    TextView trainDetailIntro;
    @BindView(R.id.train_detail_notice)
    TextView trainDetailNotice;
    @BindView(R.id.train_detail_address)
    TextView trainDetailAddress;
    @BindView(R.id.train_detail_price)
    TextView trainDetailPrice;
    @BindView(R.id.train_detail_opentime)
    TextView trainDetailOpentime;
    @BindView(R.id.train_detail_closetime)
    TextView trainDetailClosetime;
    @BindView(R.id.baoming)
    Button baoming;
    @BindView(R.id.train_fanhui)
    ImageView trainFanhui;
    private String id;
    private RetrofitListener<TrainBean> listener;
    NumberPicker np1;
    private int minPrice=1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_train_detail);
        ButterKnife.bind(this);

        np1=(NumberPicker)findViewById(R.id.np1);


        np1.setMaxValue(5);
        //设置np1的当前值
        np1.setValue(minPrice);
        np1.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                minPrice=newVal;

            }
        });
        final Intent intent = getIntent();
        id = (String) intent.getStringExtra("trainid");
        listener = new RetrofitListener<TrainBean>() {
            @Override
            public void onSuccess(TrainBean trainBean, int flag) {
                trainDetailName.setText(trainBean.getTrain_name());
                trainDetailIntro.setText(trainBean.getTrain_intro());
                trainDetailNotice.setText(trainBean.getTrain_notice());
                trainDetailAddress.setText(trainBean.getTrain_address());
                trainDetailPrice.setText(trainBean.getTrain_price());
                trainDetailOpentime.setText(trainBean.getTrain_opentime());
                trainDetailClosetime.setText(trainBean.getTrain_closetime());
                Picasso.with(TrainDetailActivity.this).load(IMAGEURL + trainBean.getTrain_pic()).into(trainDetailPic);
            }

            @Override
            public void onFail() {

            }
        };
        getTrainDetail();
        baoming.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1 = new Intent(TrainDetailActivity.this, ShoppingCartActivity.class);
                intent1.putExtra("b_id", id);
                intent1.putExtra("num_id",minPrice);
                startActivity(intent1);
                finish();
            }
        });

        trainFanhui.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent2=new Intent(TrainDetailActivity.this,FragmentActivity.class);
                startActivity(intent2);
                finish();
            }
        });
    }

    private void getTrainDetail() {
        TrainDetailModel trainDetailModel = new TrainDetailModel();
        trainDetailModel.getTrainDetail(id, listener);
    }
}
